/*
 * @name: **列表
 * @content:
 * @Author: joyce
 * @Date: 2021-05-14 10:23:13
 */
let createError = require('http-errors')
let express = require('express')
let path = require('path')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const helmet = require('helmet')
const compression = require('compression')
const morgan = require('morgan')
const expressJWT = require('express-jwt')
const app = express()

require('./utils/db')()
// Web应用安全的中间件。
app.use(helmet())
//跨域
app.use(cors())

//压缩请求 gzip是用于压缩，js、css等文件的压缩
app.use(compression())

app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded

// 为了获取 cookie
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))

app.use(morgan('tiny')) // 控制台输出日志
app.use('/', require('./routes/index.js'))
app.use('/', require('./routes/upload.js'))
app.use('/', require('./routes/user'))

app.use(function (req, res, next) {
  next(createError(404))
})

app.listen(3000, _ => console.log('server listening in http://127.0.0.1:3000'))
